package com.example.wldcmzy.study001;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/*
public class MainActivity extends Activity implements View.OnClickListener{

    private Button btn;
    private TextView txt;
    private int a;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        a = 0;
        txt = (TextView) findViewById(R.id.txt);
        btn = (Button) findViewById(R.id.btn);

        btn.setOnClickListener(this);
        txt.setOnClickListener(this);
    }

    public void onClick(View V){
        a += 1;
        txt.setText("点击次数:" + a);
    }
}
*/

public class MainActivity extends Activity {

    private Button btn;
    private TextView txt;
    private int a;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        a = 0;
        txt = (TextView) findViewById(R.id.txt);
        btn = (Button) findViewById(R.id.btn);

        txt.setOnClickListener(new View.OnClickListener(){

            public void onClick(View v){
                txt.setText("按钮被点击...");
            }
        });

        btn.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                a += 1;
                txt.setText("按钮点击次数:" + a);
            }
        });
    }

}

